﻿namespace Ocelot.Admin.Api.Application
{
    /// <summary>
    /// 路由接口
    /// </summary>
    public class RouteApiController : IDynamicApiController
    {
        private readonly IRouteService _routeService;
        public RouteApiController(IRouteService routeService)
        {
            _routeService = routeService;
        }

        #region 查询

        /// <summary>
        /// 预览路由
        /// </summary>
        /// <returns></returns>
        public async Task<string> GetRoutePreviewAsync()
        {
            return await _routeService.GetRoutePreviewAsync();
        }

        /// <summary>
        /// 分页查询路由信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task<SqlSugarPagedList<PageRouteResponse>> GetPageRouteAsync([FromQuery] PageRouteRequest request)
        {
            return await _routeService.GetPageRouteAsync(request);
        }

        /// <summary>
        /// 查询路由信息
        /// </summary>
        /// <param name="routeId"></param>
        /// <returns></returns>
        public async Task<RouteDto> GetRouteAsync(int routeId)
        {
            return await _routeService.GetRouteAsync(routeId);
        }

        #endregion

        #region 新增

        /// <summary>
        /// 新增路由信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task<int> InsertRouteAsync(RouteDto request)
        {
            return await _routeService.InsertRouteAsync(request);
        }

        #endregion

        #region 编辑

        /// <summary>
        /// 更新路由信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task<int> UpdateRouteAsync(RouteDto request)
        {
            return await _routeService.UpdateRouteAsync( request);
        }

        /// <summary>
        /// 启用或禁用路由信息
        /// </summary>
        /// <param name="routeId">路由Id</param>
        /// <param name="enabled">是否有效</param>
        /// <returns></returns>
        public async Task<string> PatchRouteAsync(int routeId, bool enabled)
        {
            return await _routeService.PatchRouteAsync(routeId, enabled);
        }
        #endregion
        #region 删除

        /// <summary>
        /// 删除路由信息
        /// </summary>
        /// <param name="routeId">路由Id</param>
        /// <returns></returns>
        public async Task<string> DeleteRouteAsync(int routeId)
        {
            return await _routeService.DeleteRouteAsync(routeId);
        }

        #endregion
    }
}